﻿
<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>创建生产计划</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <script src="~/js/layui/layui.js"></script>
    <link href="~/js/layui/css/layui.css" rel="stylesheet" />
    <link href="~/X-admin/css/xadmin.css" rel="stylesheet" />
    <script src="~/X-admin/js/jquery.min.js"></script>
    <script src="~/X-admin/js/xadmin.js"></script>
    <script src="~/js/framework/sysframework.js"></script>
    <script src="~/js/framework/commonjs.js"></script>
    <script src="~/js/sysweb/planjs.js"></script>
    <script type="text/html" id="barDemo">
        <a title="删除" href="javascript:;" lay-event="del" id="frmDel"><i class="layui-icon">&#xe640;</i></a>
    </script>
@*     <script type="text/html" id="imgTpl">
        <img src="{{d.filePath}}" />
    </script> *@
</head>
<body>
  
    <div class="layui-card" style="margin-top:10px">
        <div class="layui-card">
            <div class="layui-card-body" style="margin-top:5px">
                <button type="button" class="layui-btn" id="test-upload-normal">上传附件</button>
                @* <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 11px;">
                已上传图片：
                <div class="layui-upload-list" id="upload-demo-preview"></div>
                </blockquote> *@
            </div>
        </div>
        <div class="layui-card-body layui-table-body layui-table-main" id="layui-table-main">
            <table class="layui-hide" id="list" lay-filter="list"></table>
        </div>

    </div>
</body>
</html>


<script type="text/javascript">
    var plCode = "";
    $(function () {
        plCode = getUrlVariable("plCode");
        if (plCode == "" || plCode == "0") {

        } else {

        }
        loadData();
    });

    //获取计划附件
    function loadData(){
        layui.use('table', function () {
            var table = layui.table;
            table.render({
                elem: '#list'
                , height: 'full-200'   //固定高度-即固定表头固定第一行首行
                , cols: [[ //标题栏
                      { field: 'fileName', title: '文件名称', width: 350 }
                    , { field: 'filePath', title: '图片文件', width: 130, templet: function (d) { return '<div onclick="show_img(this)" ><img src="' + d.filePath + '" ' + 'alt="" width="50px" height="50px"></a></div>'; } }
                    , { field: 'right', align: 'center', title: '数据操作', toolbar: '#barDemo', width: 120, fixed: 'right' }

                ]], done: function (res, curr, count) {
                }
                , url: "../Plan/getDataList?dataType=file&condition=" + plCode
                , skin: 'row' //表格风格
                , even: true
                , page: false //是否显示分页
                , limits: [20, 30, 50]
                , limit: 50 //每页默认显示的数量
            });

            //监听工具条
            table.on('tool(list)', function (obj) {
                var data = obj.data;
                if (obj.event == 'del') {
                    layer.confirm('确认要删除该文件？', function (index) {
                        var info = delImg(data.id, data.fileName);
                        if (info.result) {
                            layer.msg("删除成功");
                            obj.del();
                        } else {
                            layer.msg(info.message);
                        }
                        layer.close(index);
                    });
                }
                
            });


        });
    }

    layui.use('upload', function () {
        var $ = layui.jquery, upload = layui.upload;
        //指定允许上传的文件类型

        upload.render({
            elem: '#test-upload-normal',
            url: '../Plan/UploadFiles', // 实际使用时改成您自己的上传接口即可。
            data:{plCode:plCode},
            multiple: true,
            before: function (obj) {
                //预览图片
                //obj.preview(function (index, file, result) {
                    //$('#upload-demo-preview').append('<img src="' + result + '" alt="' + file.name + '" style="width: 200px; height: 200px; " >')
                //});
            },
            done: function (res) {
                loadData();
            }
        });


    });

    //放大图片
    function show_img(t) {
        var t = $(t).find("img");
        //页面层
        layer.open({
            type: 1,
            title: '附件详情',
            skin: 'layui-layer-rim', //加上边框
            area: ['90%', '90%'], //宽高 t.width() t.height()
            shadeClose: true, //开启遮罩关闭
            end: function (index, layero) {
                return false;
            },
            content: '<div style="text-align:center"><img src="' + $(t).attr('src') + '" /></div>'
        });
    }

    //删除图片
    function delImg(id, fileName) {
        var info = undefined;
        $.ajax({
            url: "../Plan/delUploadFiles",
            data: { id: id, fileName: fileName },
            dataType: "json",
            type: "POST",
            async: false,
            success: function (data) {
                info = data;
            }
        });
        return info;
    }
   

</script>

